#include <QtOpenGL>
#include <QVector3D>
#include "cubo.h"

Cubo::Cubo(const QVector3D& center, QObject *parent):
    Object3D(center, parent)
{

}

void Cubo::drawGeometry()
{
    origin();
    glBegin( GL_QUADS );
        //X
        glNormal3f(1.0,0.0,0.0);
        glColor3f(1.0,0.0,0.0);
        glVertex3f(1.0,0.0,1.0);
        glVertex3f(1.0,0.0,0.0);
        glVertex3f(1.0,1.0,0.0);
        glVertex3f(1.0,1.0,1.0);

        //-X
        glNormal3f(-1.0,0.0,0.0);
        glColor3f(0.0,1.0,1.0);
        glVertex3f(0.0,0.0,0.0);
        glVertex3f(0.0,0.0,1.0);
        glVertex3f(0.0,1.0,1.0);
        glVertex3f(0.0,1.0,0.0);

        //Y
        glNormal3f(0.0,1.0,0.0);
        glColor3f(0.0,1.0,0.0);
        glVertex3f(1.0,1.0,1.0);
        glVertex3f(1.0,1.0,0.0);
        glVertex3f(0.0,1.0,0.0);
        glVertex3f(0.0,1.0,1.0);

        //-Y
        glNormal3f(0.0,-1.0,0.0);
        glColor3f(1.0,0.0,1.0);
        glVertex3f(0.0,0.0,0.0);
        glVertex3f(1.0,0.0,0.0);
        glVertex3f(1.0,0.0,1.0);
        glVertex3f(0.0,0.0,1.0);


        //Z
        glNormal3f(0.0,0.0,1.0);
        glColor3f(0.0,0.0,1.0);
        glVertex3f(0.0,0.0,1.0);
        glVertex3f(1.0,0.0,1.0);
        glVertex3f(1.0,1.0,1.0);
        glVertex3f(0.0,1.0,1.0);

        //-Z
        glNormal3f(0.0,0.0,-1.0);
        glColor3f(1.0,1.0,0.0);
        glVertex3f(0.0,0.0,0.0);
        glVertex3f(0.0,1.0,0.0);
        glVertex3f(1.0,1.0,0.0);
        glVertex3f(1.0,0.0,0.0);

        glEnd();

}

void Cubo::origin()const
{
    glDisable( GL_LIGHTING );
    glBegin( GL_LINES );
        glColor3f(1.0, 0.0, 0.0);
        glVertex3f(0.0, 0.0, 0.0);
        glVertex3f(1.0, 0.0, 0.0);

        glColor3f(0.0, 1.0, 0.0);
        glVertex3f(0.0, 0.0, 0.0);
        glVertex3f(0.0, 1.0, 0.0);

        glColor3f(0.0, 0.0, 1.0);
        glVertex3f(0.0, 0.0, 0.0);
        glVertex3f(0.0, 0.0, 1.0);
    glEnd();
    glEnable( GL_LIGHTING );
}
